<div class="model_actions_toolbar">
    <?php $this->widget('backend.components.ModelActions'); ?>
</div>

<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->baseUrl; ?>/assets/backend/books.css" />

<div class="book">
    <div class="title">
        <?php echo CHtml::encode($book->name); ?>
    </div>
    <div class="book_infos">
        <div class="cover" id="book_cover">
            <?php echo CHtml::link(CHtml::image($book->coverSource, $book->name), array('viewChapterContents', 'bid' => $book->id)); ?>
        </div>
        <div style="float: left; padding-left: 20px;">
            <p>Posted at <?php echo date('Y-m-d H:m:s', $book->created); ?></p>
            <p>
                <?php echo Yii::t('book', 'author'); ?>: <?php echo $book->author; ?>
                <span></span>
                <?php echo Yii::t('book', 'published_unit'); ?>: <?php echo $book->published_unit; ?>
            </p>
        </div>
    </div>
    <div class="book_summary">
        <?php
        $this->beginWidget('CMarkdown', array('purifyOutput' => true));
        echo CUtil::substr(CModifier::Html2Text($book->summary, 1), 300);
        $this->endWidget();
        ?>
    </div>
    <div class="box">
        <div id="book_chapter_tree" class="chapter_trees">
            <?php
            $this->widget('CTreeView', array(
                'persist' => 'cookie', 'data' => $chapter_trees, 'animated' => 'fast', 'htmlOptions' => array(
                'id' => 'treeview', 'class' => 'filetree folder'
                )
            ));
            ?>
        </div>
        <div class="chapter_contents_list">
            <ul>
                <?php
                foreach ($chapter_contents as $chapter_content):
                    $url = $this->createUrl('', array('bid' => $book->id,
                        'category' => $chapter_content->category_id,
                        'content_id' => $chapter_content->id
                        )) . "#c{$chapter_content->id}";
                    
                ?>
                <li><?php echo CHtml::link(CHtml::encode($chapter_content->title), "#c{$chapter_content->id}"); ?></li>
                <?php endforeach; ?>
            </ul>
        </div>
    </div>

    <div class="box">
        <!-- begin -->
            <div style="">
                <?php
                echo CHtml::beginForm(array('viewChapterContents',
                    'bid' => Yii::app()->request->getParam('bid'),
                    'node' => Yii::app()->request->getParam('node')),
                    'post'
                );
                echo CHtml::submitButton(Yii::t('book', 'add_chapter_content'), array('class' => 'btn'));
                echo CHtml::endForm();
                ?>
            </div>

        <div id="form" class="commend" style="clear: both;">
                <?php if (Yii::app()->user->hasFlash('add_chapter_content_success')): ?>
                <div class="success">
                    <?php echo Yii::app()->user->getFlash('add_chapter_content_success'); ?>
                </div>
                <?php elseif (Yii::app()->user->hasFlash('update_chapter_content_success')): ?>
                <div class="success">
                    <?php echo Yii::app()->user->getFlash('update_chapter_content_success'); ?>
                </div>
                <?php endif; ?>
                <?php
                $this->renderPartial('/books/_chapterContent',array(
                    'content' => $content
                ));
                ?>
            </div>
            <!-- //end -->
    </div>

    <div>
        <!-- book chapter contents -->
        <?php
        foreach ($chapter_contents as $chapter_content):
            $edit_url = $this->createUrl('viewChapterContents', array(
                'bid' => $book->id,
                'category' => $chapter_content->category_id,
                'content_id' => $chapter_content->id
            ));
        ?>
        <div id="c<?php echo $chapter_content->id; ?>" class="chapter_content_box">
            <h1 class="title">
                <?php echo CHtml::encode($chapter_content->title); ?>
                <span><?php echo CHtml::link('edit', "{$edit_url}#form"); ?></span>
                <span><a href="#book_chapter_tree">Top</a></span>
            </h1>
            <div class="chapter_content_body">
                <?php
                $this->beginWidget('CMarkdown', array('purifyOutput' => true));
                echo $chapter_content->body;
                $this->endWidget();
                ?>
            </div>
            <div class="chapter_content_infos">
                <?php echo Yii::t('bookChapterContent', 'created'); ?>
                : <?php echo date('Y-m-d H:m:s', $chapter_content->created); ?>
                <span></span>
                <?php echo Yii::t('bookChapterContent', 'updated'); ?>
                : <?php echo date('Y-m-d H:m:s', $chapter_content->created); ?>
            </div>
        </div>
        <?php endforeach; ?>
        <!-- // book chapter contents -->
    </div>

</div>
